package odl;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class Schema extends OdlElement {
	private Vector<Interface> interfaces;
	
	public Schema() {
		super();
		setInterfaces(new Vector<Interface>());
	}
	
	public Schema(String _name) {
		super(_name);
		setInterfaces(new Vector<Interface>());
	}
	
	public Interface getInterface(String _name)
	{
		for(Interface i : interfaces){
			if (i.getName().equals(_name)) 
			{
				return i;
			}
		}
		return null;
	}
	
	public void generateCSV(File output) throws IOException
	{
		FileWriter fw = new FileWriter(output);
		String currentLine ="interface, ANA, NOO, NOA, CBI, NOR, RPL, DIT, IDL, NOC, NOD\n";
		fw.write(currentLine);
		for(Interface I : interfaces)
		{
			float[] metricsValues = I.getMetricsValues();
			currentLine=I.getName();
			for(int i=0;i<metricsValues.length;i++)
				currentLine+=","+metricsValues[i];
			currentLine+="\n";
			fw.write(currentLine);
		}
		fw.close();
	}

	public Vector<Interface> getInterfaces() {
		return interfaces;
	}

	public Vector<String> getInterfacesNames() {
		Vector<String> R = new Vector<String>();
		for(Interface i : interfaces)
		{
			R.add(i.getName());
		}
		return R;
	}
	
	private void setInterfaces(Vector<Interface> interfaces) {
		this.interfaces = interfaces;
	}

	public void updateContent(){
		for(Interface i : interfaces){
			i.updateContent();
		}
	}

	public void calculateMetrics(){
		for(Interface i : interfaces){
			i.calculateMetrics();
		}
	}
}
